package com.jinzhi.jzweb.controller;


import java.util.*;

import com.jinzhi.jzweb.domain.ArchivesDO;
import com.jinzhi.jzweb.service.ArchivesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.ArchivesFollowDO;
import com.jinzhi.jzweb.service.ArchivesFollowService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2021-08-09 09:27:28 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/archivesFollow")
public class ArchivesFollowController extends BaseController {
	@Autowired
	private ArchivesFollowService archivesFollowService;
	@Autowired
	private ArchivesService archivesService;
	@GetMapping()
	@RequiresPermissions("jzweb:archivesFollow:archivesFollow")
	String ArchivesFollow(){
	    return "jzweb/archivesFollow/archivesFollow";
	}

	@GetMapping("/archivesFollowS")
	@RequiresPermissions("jzweb:archives:archivesFollowS")
	String Archives(){
		return "archivesedit";
	}

	@ResponseBody
	@GetMapping("/lists")
	@RequiresPermissions("jzweb:archives:archivesFollowS")
	public Result<Page<ArchivesDO>> list(ArchivesDO archivesDTO){
		// 查询列表数据
		Page<ArchivesDO> page = archivesService.selectPage(getPage(ArchivesDO.class),
				archivesService.convertToEntityWrapper().orderBy("actual_money", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
			ArchivesDO obj = (ArchivesDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
		return Result.ok(page);
	}

	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:archivesFollow:archivesFollow")
	public Result<Page<ArchivesFollowDO>> list(ArchivesFollowDO archivesFollowDTO){
		// 查询列表数据
		Page<ArchivesFollowDO> page = archivesFollowService.selectPage(getPage(ArchivesFollowDO.class),
					archivesFollowService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				ArchivesFollowDO obj = (ArchivesFollowDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:archivesFollow:add")
	String add(){
	    return "jzweb/archivesFollow/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:archivesFollow:edit")
	String edit(@PathVariable("id") Long id,Model model){
		ArchivesFollowDO archivesFollow = archivesFollowService.selectById(id);
		model.addAttribute("archivesFollow", archivesFollow);
	    return "jzweb/archivesFollow/edit";
	}
	
	@Log("添加")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:archives:add")
	public Result<String> save( ArchivesFollowDO archivesFollow){
		archivesFollowService.insert(archivesFollow);
        return Result.ok();
	}
	
	@Log("修改")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:archives:edit")
	public Result<String>  update( ArchivesFollowDO archivesFollow){
		boolean update = archivesFollowService.updateById(archivesFollow);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:archivesFollow:remove")
	public Result<String>  remove( Long id){
		archivesFollowService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:archivesFollow:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		archivesFollowService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}




}
